home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hamradio / ftp4w.zip / ftp4w.h < prev    next >
C/C++ Source or Header  |  1994-11-15  |  10KB  |  217 lines

  1.  
  2. /* *************************************************************** */
  3. /*                                                                 */
  4. /*                                                                 */
  5. /*                                                                 */
  6. /*    FTP4W.DLL  (Version 1.1)                                     */
  7. /*                                                                 */
  8. /*                                                                 */
  9. /*                                   By Ph. Jounin (SNCF 71-26-12) */
  10. /*                                        Internet ark@ifh.sncf.fr */
  11. /*                                        Thanks to Santanu Lahiri */
  12. /* *************************************************************** */
  13.  
  14.  
  15. #ifndef WFTP_API
  16.  
  17. #include <winsock.h>
  18.  
  19. #ifdef DEBUG
  20. #  define  FTP_DATABUFFER  256                 /* slown down the transfer */
  21. #else
  22. #  define  FTP_DATABUFFER  1450 /* a good value for X25/Ethernet/Token Ring */
  23. #endif
  24.  
  25.  
  26.  
  27. /* ----------------------------------------------------------- */
  28.  
  29. /* ASCII or binary tranfser */
  30. #define   TYPE_A   'A'
  31. #define   TYPE_I   'I'
  32.  
  33.  
  34. /* ----------------------------------------------------------- */
  35. /*              Return codes of FTP functions                  */
  36. /* ----------------------------------------------------------- */
  37. /* success */
  38. #define   FTPERR_OK                    0 /* succesful function                */
  39. #define   FTPERR_ENTERPASSWORD         1 /* userid need a password            */
  40. #define   FTPERR_ACCOUNTNEEDED         2 /* user/pass OK but account required */
  41. #define   FTPERR_CANCELBYUSER         -1 /* Transfer aborted by user FtpAbort */
  42. /* user's or programmer's Errors  */
  43. #define   FTPERR_INVALIDPARAMETER   1000 /* Error in parameters               */
  44. #define   FTPERR_SESSIONUSED        1001 /* User has already a FTP session    */
  45. #define   FTPERR_NOTINITIALIZED     1002 /* FtpInit has not been call         */
  46. #define   FTPERR_NOTCONNECTED       1003 /* User is not connected to a server */
  47. #define   FTPERR_CANTOPENFILE       1004 /* can not open specified file       */
  48. #define   FTPERR_CANTWRITE          1005 /* can't write into file (disk full?)*/
  49. #define   FTPERR_NOACTIVESESSION    1006 /* FtpRelease without FtpInit        */
  50. #define   FTPERR_STILLCONNECTED     1007 /* FtpRelease without any Close      */
  51. #define   FTPERR_SERVERCANTEXECUTE  1008 /* file action not taken             */
  52. #define   FTPERR_LOGINREFUSED       1009 /* Server rejects usrid/passwd       */
  53. #define   FTPERR_NOREMOTEFILE       1010 /* server can not open file          */
  54. #define   FTPERR_TRANSFERREFUSED    1011 /* Host refused the transfer         */
  55. #define   FTPERR_WINSOCKNOTUSABLE   1012 /* A winsock.DLL ver 1.1 is required */
  56. /* TCP errors */
  57. #define   FTPERR_UNKNOWNHOST        2001 /* can not resolve host adress       */
  58. #define   FTPERR_NOREPLY            2002 /* host does not send an answer      */
  59. #define   FTPERR_CANTCONNECT        2003 /* Error during connection           */
  60. #define   FTPERR_CONNECTREJECTED    2004 /* host has no FTP server            */
  61. #define   FTPERR_SENDREFUSED        2005 /* can't send data (network down)    */
  62. #define   FTPERR_DATACONNECTION     2006 /* connection on data-port failed    */
  63. #define   FTPERR_TIMEOUT            2007 /* timeout occured                   */
  64. /* FTP errors */
  65. #define   FTPERR_UNEXPECTEDANSWER   3001  /* answer was not expected          */
  66. #define   FTPERR_CANNOTCHANGETYPE   3002  /* host rejects the TYPE command    */
  67. /* Resource errors */
  68. #define   FTPERR_CANTCREATEWINDOW   5002  /* Insufficent free resources       */
  69. #define   FTPERR_INSMEMORY          5003  /* Insuffisent Heap memory          */
  70. #define   FTPERR_CANTCREATESOCKET   5004  /* no more socket                   */
  71. #define   FTPERR_CANTBINDSOCKET     5005  /* bind is not succesful            */
  72.  
  73.  
  74. /* ----------------------------------------------------------- */
  75.  
  76. struct S_FtpData
  77. {
  78.    SOCKET   ctrl_socket;    /* control stream      init INVALID_SOCKET */
  79.    SOCKET   data_socket;    /* data stream         init INVALID_SOCKET */
  80.    SOCKET   listen_socket;  /* listen socket       init INVALID_SOCKET */
  81.    char     cType;          /* type (ASCII/binary) init TYPE_A         */
  82.    BOOL     bVerbose;       /* verbose mode        init FALSE          */ 
  83.    unsigned nPort;          /* connexion Port      init FTP_DEFPORT    */
  84.    unsigned nTimeOut;       /* TimeOut in seconds  init FTP_DEFTIMEOUT */
  85.    char     szInBuf [1024]; /* incoming Buffer                         */
  86.    char     szOutBuf [512]; /* outgoing buffer                         */
  87.    struct sockaddr_in saSockAddr;   
  88.    struct sockaddr_in saAcceptAddr;
  89. }; /* struct S_FtpData */
  90.  
  91.  
  92. struct S_FileTrf 
  93. {
  94.    HFILE    hf;         /* handle of the file which is being transfered */
  95.    unsigned nCount;     /* number of writes/reads made on a file        */
  96.    unsigned nAsyncAlone;/* pause each N frame in Async mode  (Def 40)   */
  97.    unsigned nAsyncMulti;/* Idem but more than one FTP sssion (Def 10)   */
  98.    unsigned nDelay;     /* time of the pause in milliseconds            */
  99.    BOOL     bAborted;   /* data transfer has been canceled              */
  100.    char     szBuf[FTP_DATABUFFER]; /* Data buffer                       */
  101.    BOOL     bNotify;    /* application receives a msg each data packet  */
  102.    BOOL     bAsyncMode; /* synchronous or asynchronous Mode             */
  103.    LONG     lPos;       /* Bytes transfered                             */
  104.    LONG     lTotal;     /* bytes to be transfered                       */
  105. }; /* struct S_FileTrf */
  106.  
  107. struct S_Msg
  108. {
  109.    HWND          hParentWnd;        /* window which the msg is to be passed   */
  110.    UINT          nCompletedMessage; /* msg to be sent at end of the function  */
  111. };  /* struct S_Msg */
  112.  
  113.  
  114. struct S_Verbose
  115. {
  116.    HWND          hVerboseWnd;  /* window which the message is to be passed    */
  117.    UINT          nVerboseMsg;  /* msg to be sent each time a line is received */
  118. };
  119.  
  120. /* global structure */
  121. struct S_ProcData
  122. {  
  123.    /* task data */
  124.    HTASK      hTask;              /* Task Id                              */
  125.    HWND       hFtpWnd;            /* Handle of the internal window        */
  126.    HWND       hParentWnd;         /* handle given to the FtpInit function */
  127.    HINSTANCE  hInstance;          /* Task Instance                        */
  128.  
  129.    /* Mesasge information */
  130.    struct S_Msg      Msg;      
  131.    struct S_Verbose  VMsg;      
  132.                                                                
  133.    /* File information */
  134.    struct S_FileTrf  File;  
  135.  
  136.    /* Ftp information */
  137.    struct S_FtpData   ftp;
  138.    
  139.    /* Linked list */
  140.    struct S_ProcData far *Next;
  141.    struct S_ProcData far *Prev;
  142. }; /* struct S_ProcData */
  143.  
  144. typedef struct S_ProcData far * LPProcData;
  145. typedef struct S_FtpData far *  LPFtpData;
  146.  
  147. /* **************************************************************** */
  148. /*                                                                  */
  149. /*   Parameters                                                     */
  150. /*                                                                  */
  151. /* **************************************************************** */
  152.  
  153. #define  FtpBytesTransfered()       FtpDataPtr()->File.lPos
  154. #define  FtpBytesToBeTransfered()   FtpDataPtr()->File.lTotal
  155.  
  156. #define  FtpSetDefaultTimeOut(x)    FtpDataPtr()->ftp.nTimeOut=x /* x seconds */
  157. #define  FtpSetDefaultPort(x)       FtpDataPtr()->ftp.nPort=x
  158. #define  FtpSetAsynchronousMode()   FtpDataPtr()->File.bAsyncMode=TRUE
  159. #define  FtpSetSynchronousMode()    FtpDataPtr()->File.bAsyncMode=FALSE
  160. #define  FtpIsAsynchronousMode()   (FtpDataPtr()->File.bAsyncMode)
  161. #define  FtpSetNewDelay(x)          FtpDataPtr()->File.nDelay=x /* x millisec */
  162. #define  FtpSetNewSlices(x,y)       FtpDataPtr()->File.nAsyncAlone=x, \
  163.                                     FtpDataPtr()->File.nAsyncAlone=y
  164.  
  165.  
  166. /* **************************************************************** */
  167. /*                                                                  */
  168. /*                    P R O T O T Y P E S                           */
  169. /*                                                                  */
  170. /* **************************************************************** */
  171.  
  172. /* Utilities functions */
  173. LPProcData PASCAL FAR  FtpDataPtr (void);
  174. int PASCAL FAR WEP (int nType);
  175. int PASCAL FAR FtpSetVerboseMode (BOOL bVerboseMode, HWND hVerboseWnd, UINT wMsg);
  176.  
  177. /* Init functions */
  178. int PASCAL FAR FtpRelease (void);
  179. int PASCAL FAR FtpInit (HWND hParentWnd);
  180.  
  181. /* Connection */
  182. int PASCAL FAR FtpLogin (LPSTR szHost, LPSTR szUser, LPSTR szPasswd,
  183.                          HWND hParentWnd, UINT wMsg);
  184. int PASCAL FAR FtpOpenConnection (LPSTR szHost);
  185. int PASCAL FAR FtpCloseConnection (void);
  186. int PASCAL FAR FtpLocalClose (void);
  187.  
  188. /* authentification */
  189. int PASCAL FAR  FtpSendUserName (LPSTR szUserName);
  190. int PASCAL FAR  FtpSendPasswd (LPSTR szPasswd);
  191.  
  192. /* commands */
  193. int PASCAL FAR FtpHelp  (LPSTR szArg, LPSTR szBuf, UINT uBufSize);
  194. int PASCAL FAR FtpCWD   (LPSTR szPath);
  195. int PASCAL FAR FtpQuote (LPSTR szCmd, LPSTR szReplyBuf, UINT uBufSize);
  196. int PASCAL FAR FtpSetType  (char cType);
  197.  
  198. /* file transfer */
  199. int PASCAL FAR FtpAbort (void);
  200. int PASCAL FAR FtpSendFile (LPSTR szLocal, LPSTR szRemote, char cType, 
  201.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  202. int PASCAL FAR FtpRecvFile (LPSTR szRemote, LPSTR szLocal, char cType, 
  203.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  204.  
  205.  
  206. DWORD PASCAL FAR FtpGetFileSize (void);
  207.  
  208. /* Directory */
  209. int PASCAL FAR FtpDir (LPSTR szDef, LPSTR szLocalFile,
  210.                        BOOL  bLongDir, HWND  hParentWnd, UINT wMsg);
  211.  
  212. /* _______________________________________________________________ */
  213.  
  214. #define WFTP_API loaded
  215. #endif /* ifndef WFTP_API */
  216.  
  217.